package com.fl.demo.utills;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.URL;

public class HtmlParseUtil {

    public static void main(String[] args) throws IOException {
        //获取请求 https://search.jd.com/Search?keyword=java
        //前提，需要联网，ajax 不能获取到
        String url = "https://www.bilibili.com/";
        //解析网页。（Jsoup 返回是Document就是浏览器Document对象）
            Document document = Jsoup.parse(new URL(url), 3000);
           Elements element =  document.getElementsByClass("card-pic");
           for (Element element1 :element){
               String img = element1.getElementsByTag("img").eq(0).attr("src");
               System.out.println("===============");
               System.out.println(img);
           }
//        System.out.println(element);
        //获取所有的a标签
//        Elements elements = document.getElementsByTag("a");
//        for (Element e1 : elements){
//            System.out.println(e1.html());
//        }
    }
}
